//
//  RedView.m
//  TouchExplorer
//
//  Created by student on 16/3/17.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "RedView.h"

@implementation RedView
{
    CGPoint pointXY;// 距离中心点的偏移
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.superview];
    
    // 计算触摸点距离中心点的偏移
    pointXY = CGPointMake(point.x - self.center.x, point.y - self.center.y);

}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.superview];
    self.center = CGPointMake(point.x - pointXY.x, point.y - pointXY.y);
}

@end
